#include "store.h"
#include "storage_filter.h"
#include "storage_strategy.h"

namespace fusion_perception {

Store::Store(std::shared_ptr<StorageStrategy> storageStrategySptr, std::shared_ptr<StorageFilter> storageFilterSptr)
    : storageStrategySptr_(storageStrategySptr)
    , storageFilterSptr_(storageFilterSptr)
{
}

void Store::push(ObjectSptrVector msg)
{
    for (auto begin = msg.begin(); begin != msg.end();) {
        if (!storageFilterSptr_->filtering((*begin)->id)) {
            begin = msg.erase(begin);
        } else {
            ++begin;
        }
    }

    storageStrategySptr_->push(msg);
}

ObjectSptrVector Store::take(int64_t microTs)
{
    return storageStrategySptr_->take(microTs);
}

}